package ext.acae2.dms.web.input;

import wt.fc.ObjectReference;
import wt.fc.PersistenceHelper;
import wt.util.WTException;
import wt.util.WTMessage;
import wt.workflow.engine.WfActivity;
import wt.workflow.engine.WfBlock;
import wt.workflow.engine.WfContainer;
import wt.workflow.engine.WfProcess;


import ext.acae2.dms.resource.DataExchangeResource;

public class DataInputHelper {
	private static final String RESOURCE = DataExchangeResource.class.getName();
	public static final String HTML_DATA_SEND_LINK="<a href=\"netmarkets/jsp/ext/acae2/dms/dataImport.jsp?procOid=";
	public static final String HTML_LINK_BLANK_MID = "\" target=\"_blank\">";
	public static final String HTML_LINK_AFTER = "</a>";
	
	/**
	 * 构造Link
	 * @param pbo
	 * @return
	 * @throws WTException 
	 */
	public static String getDataImportLink(Object self) throws WTException{
		String displayValue = WTMessage.getLocalizedMessage(RESOURCE, DataExchangeResource.DATA_IMPORT_DESCRIPTION);
		if(self instanceof ObjectReference){
			ObjectReference oref = (ObjectReference)self;
			WfActivity wfactivity = (WfActivity)oref.getObject();
			WfContainer wfcont = (WfContainer) wfactivity.getParentProcessRef().getObject();
			if (wfcont instanceof WfBlock) {
				WfBlock wb = (WfBlock)wfcont;
				wfcont = wb.getParentProcess();
			}
			WfProcess process = (WfProcess) wfcont;
			String procOid = PersistenceHelper.getObjectIdentifier(process).toString();
			String link = HTML_DATA_SEND_LINK + procOid+ HTML_LINK_BLANK_MID + displayValue
					+ HTML_LINK_AFTER;
			return link;
		}else{
			return "<a href=\"#\">"+displayValue+"</a>";
		}
	}

}
